package com.tungse.timerwheel;

import org.junit.Test;

import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Demo {
    static ThreadPoolExecutor threadPool =
            new ThreadPoolExecutor(10, 10, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10));

    public static void main(String[] args) {
        TimerWheel timerWheel = new TimerWheel();
        for (int i = 0; i < 100; i++) {
            final int fi = i;
            timerWheel.addDelayTask(() -> {
                System.out.println(fi);
            }, 1000L * i);
        }
    }

    @Test
    public void test001() {
        MpscTaskQueue mpscTaskQueue = new MpscTaskQueue();
        Future<?> submit = threadPool.submit(() -> {
            for (int i = 0; i < 63; i++) {
                final int fi = i;
                TimerWheel.DelayTask task = new TimerWheel.DelayTask(() -> {
                    System.out.println(fi);
                }, 1000L * i);
                mpscTaskQueue.pushTask(task);
            }
        });
        System.out.println("submit = " + submit);
        Future<List<Runnable>> submit1 = threadPool.submit(() -> {
            long tickTime =  60 * 1000;
            return mpscTaskQueue.removeAndReturnShouldRun(tickTime);
        });
        System.out.println("submit1 = " + submit1);

    }
}